//
//  FirstTableViewCell.m
//  UI---8.9--婚礼记
//
//  Created by 北风 on 14-10-4.
//  Copyright (c) 2014年 高敬轩. All rights reserved.
//

#import "ScrollViewTableViewCell.h"

@implementation ScrollViewTableViewCell
- (void)dealloc
{
    [_secoll release];
    [_imageView1 release];
    [_imageView2 release];
    [_imageView3 release];
    [super dealloc];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        _secoll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 130)];
        [_secoll setContentSize:CGSizeMake(4 * 320, 0)];
        _secoll.pagingEnabled = YES;
        _secoll.delegate = self;
        [_secoll setBackgroundColor:[UIColor cyanColor]];
        [self.contentView addSubview:_secoll];
        
        _imageView1 = [[UIImageView alloc] init];
        _imageView2 = [[UIImageView alloc] init];
        _imageView3 = [[UIImageView alloc]init];
        _imageView4 = [[UIImageView alloc] init];
        
        
        
        [_imageView1 setFrame:CGRectMake(0, 0, 320, 140)];
     [_imageView1 setBackgroundColor:[UIColor redColor]];
        [self.secoll addSubview:_imageView1];
        
        [_imageView2 setFrame:CGRectMake(self.imageView1.frame.origin.x + self.imageView1.frame.size.width, 0, self.imageView1.frame.size.width, 140)];
        [_imageView2  setBackgroundColor:[UIColor cyanColor]];
        [self.secoll addSubview:_imageView2];
        
        [_imageView3 setFrame:CGRectMake(_imageView2.frame.origin.x + _imageView2.frame.size.width, 0, self.imageView2.frame.size.width, self.imageView2.frame.size.height)];
        [_imageView3 setBackgroundColor:[UIColor orangeColor]];
        [self.secoll addSubview:_imageView3];
        
        
        [_imageView4 setFrame:CGRectMake(_imageView3.frame.origin.x + _imageView3.frame.size.width, 0, self.imageView3.frame.size.width, self.imageView3.frame.size.height)];
        [self.secoll addSubview:_imageView4];
        
        
        
        [NSTimer scheduledTimerWithTimeInterval:1.3 target:self selector:@selector(scrollView) userInfo:nil repeats:YES];
        
        _page = [[UIPageControl alloc] initWithFrame:CGRectMake(_imageView1.frame.size.width / 2 - 60, 90, 100, 50)];
        [_page addTarget:self action:@selector(pageControlAction) forControlEvents:UIControlEventValueChanged];
        _page.hidesForSinglePage = YES;
        _page.userInteractionEnabled = NO;
        _page.numberOfPages = 4;
        
        [self.contentView insertSubview:_secoll atIndex:0];
        [self.contentView addSubview:_page];
        
        
    }
    return self;
}




-(void)scrollView{
    NSInteger pianYi = _secoll.contentOffset.x;
    pianYi += 320;
    if (pianYi > 320 * 3) {
        pianYi = 0;
    }
    [self.secoll setContentOffset:CGPointMake(pianYi , 0) animated:NO];
}

-(void)pageControlAction
{
    _secoll.contentOffset = CGPointMake(_page.currentPage * 320, 0);
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int index = _secoll.contentOffset.x;
    _page.currentPage = index / 320;
    
}



- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
